package com.squirrel.serialportcore.common;

import com.squirrel.serialportcore.entity.mapper.PortQueueMapper;
import com.squirrel.serialportcore.entity.property.JsonProperty;
import gnu.io.CommPortIdentifier;
import org.springframework.util.StopWatch;

import java.util.HashMap;
import java.util.Map;

/**
 * 全局静态存储地
 * 该存储池主要存储spring初始化之前就填埋好的数据
 *
 * @author Squbi
 * @date 2021/3/21 18:15
 */

public class CommonBase {
    private CommonBase() {
    }

    /**
     * totalInit 全局初始化开关 默认为false
     * jsonProperty spc.json读取的配置属性
     * portQueueName 串口对应的队列名字 <String, PortQueueMapper> 串口名/串口对应队列名集合
     * serialPortsIdentifier 初始化的接口集合 <String, CommPortIdentifier> 串口名/端口识别器
     *
     * @author Squbi
     * @date 2021/3/23 11:35
     */
    private static StopWatch stopWatch = new StopWatch();

    private static volatile boolean totalInit = false;

    private static JsonProperty jsonProperty;

    private static Map<String, PortQueueMapper> portQueueName = new HashMap<>();

    private static Map<String, CommPortIdentifier> serialPortsIdentifier = new HashMap<>();


    /**
     * 失血模型
     * ----------------------------------------
     */

    public static StopWatch getStopWatch() {
        return stopWatch;
    }

    public static void setStopWatch(StopWatch stopWatch) {
        CommonBase.stopWatch = stopWatch;
    }

    public static boolean isTotalInit() {
        return totalInit;
    }

    public static void setTotalInit(boolean totalInit) {
        CommonBase.totalInit = totalInit;
    }

    public static Map<String, CommPortIdentifier> getSerialPortsIdentifier() {
        return serialPortsIdentifier;
    }

    public static void setSerialPortsIdentifier(Map<String, CommPortIdentifier> serialPortsIdentifier) {
        CommonBase.serialPortsIdentifier = serialPortsIdentifier;
    }

    public static Map<String, PortQueueMapper> getPortQueueName() {
        return portQueueName;
    }

    public static void setPortQueueName(Map<String, PortQueueMapper> portQueueName) {
        CommonBase.portQueueName = portQueueName;
    }

    public static JsonProperty getJsonProperty() {
        return jsonProperty;
    }

    public static void setJsonProperty(JsonProperty jsonProperty) {
        CommonBase.jsonProperty = jsonProperty;
    }
}
